<?php

namespace july\julyadmin\builder\traits\actions;

use july\julyadmin\builder\Form;
/**
 * 详情
 */

trait HasView
{
    public function view()
    {
        $pk      = input($this->getPk());
        $builder = $this->builder();
        $data    = $this->dataModel->where([$this->getPk() => $pk])->find();
        if (!$data) {
            $info = ['code' => '500', 'msg' => '要查看的数据不存在'];
            return view('error/error', ['info' => $info]);
            exit;
        }
        $form         = new Form($builder);
        $form->isEdit = 1;
        $form->method = 'post';
        $form->data   = $data;
        $form->pk     = $this->getPk();
        $form->isView = true;
        $this->buildForm($form, $form->isEdit, $data);
        $form->render();
    }
}
